From 96f900ef40028defeff979e28121e48a46941157 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Mon, 14 Jul 2008 10:04:41 +0100 Subject: [PATCH] Choice of network interface for establishing a bridge on if NFSROOT is used This patch fixes a problem related to machines that are booted using nfsroot ( '/' provided via nfs). Previously the code was assuming that nfsroot would be provided via eth0. Now this additional code checks over which interface the nfsroot is provided after detecting that nfsroot is actually being used. To determine from where nfsroot is mounted I am reading the kernel command line (/proc/cmdline) and filter for an argument starting with 'nfsroot=' and determine the nfs server's IP address by assuming the format 'nfsroot=:' - if there's a better way of doing this, please let me know. After that I determine the interface over which this IP address would be accessed using 'ip route get
'. Then I compare that interface against a previously determined default interface and if they are equal return a value that causes an alternative interface to be chosen. Signed-off-by: Stefan Berger --- tools/examples/network-bridge | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/examples/network-bridge b/tools/examples/network-bridge index 245f7ce9f0..9d7be4e2e5 100755 --- a/tools/examples/network-bridge +++ b/tools/examples/network-bridge @@ -60,7 +60,18 @@ is_network_root () { local rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' /etc/mtab) local rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab) - [[ "$rootfs" =~ "^nfs" ]] || [[ "$rootopts" =~ "_netdev" ]] && return 0 || return 1 + [[ "$rootfs" =~ "^nfs" ]] || [[ "$rootopts" =~ "_netdev" ]] && has_nfsroot=1 || has_nfsroot=0 + if [ $has_nfsroot -eq 1 ]; then + local bparms=$(cat /proc/cmdline) + for p in $bparms; do + local ipaddr=$(echo $p | awk /nfsroot=/'{ print substr($1,9,index($1,":")-9) }') + if [ "$ipaddr" != "" ]; then + local nfsdev=$(ip route get $ipaddr | awk /$ipaddr/'{ print $3 }') + [[ "$nfsdev" == "$netdev" ]] && return 0 || return 1 + fi + done + fi + return 1 } find_alt_device () { -- 2.30.2